def remove_dup(nums, K):
    slow = K
    for fast in range(K, len(nums)):
        pre = nums[slow - K]
        cur = nums[fast]
        if pre != cur:
            nums[slow - K] = cur
            slow += 1
    return slow
